package com.practice.LocalDateTime和ZonedDateTime等java8中全新的时间API相关操作;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

/**
 * @program: tenghw-practice-demo
 * @author: tenghw
 * @create: 2024-01-14 12:53
 * @Version 1.0
 * @description: 获取当前数据
 **/
public class Demo1 {
    public static void main(String[] args) {
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        System.out.println(currentDate);

        // 获取当前时间
        LocalTime currentTime = LocalTime.now();
        System.out.println(currentTime);

        // 获取当前日期和时间
        LocalDateTime currentDateTime = LocalDateTime.now();
        System.out.println(currentDateTime);

        // 格式化当前日期和时间
        DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy年MM月dd");
        // 使用DateTimeFormatter默认提供的格式对时间格式化
        DateTimeFormatter formatter3 = DateTimeFormatter.ISO_DATE_TIME;

        System.out.println(currentDateTime.format(formatter1));
        System.out.println(currentDateTime.format(formatter2));
        System.out.println(currentDateTime.format(formatter3));
    }

}